﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Obra.SmugMug.Api
{
    /// <summary>
    /// XML response following a file upload to SmugMug.
    /// </summary>
    // <rsp stat="ok">
    //   <method>smugmug.images.upload</method>
    //   <Image id="1040" Key="ixgKE" URL="http://example.smugmug.com/gallery/1040_FxWoe#5_qvUHy"/>
    // </rsp>
    [XmlRoot("rsp")]
    public class UploadResponse
    {
        [XmlAttribute("stat")]
        public string Status
        {
            get;
            set;
        }

        public bool IsSuccess()
        {
            return this.Status == "ok";
        }

        [XmlElement("method")]
        public string Method
        {
            get;
            set;
        }

        [XmlElement("Image")]
        public UploadImage Image
        {
            get;
            set;
        }

        [XmlElement("err")]
        public Error Error
        {
            get;
            set;
        }
    }

    public class UploadImage
    {
        [XmlAttribute("id")]
        public int Id
        {
            get;
            set;
        }

        [XmlAttribute("Key")]
        public string Key
        {
            get;
            set;
        }

        [XmlAttribute("URL")]
        public string UrlString
        {
            get;
            set;
        }

        public Uri Uri
        {
            get { return new Uri(this.UrlString); }
        }
    }

    public class Error
    {
        [XmlAttribute("code")]
        public int Code
        {
            get;
            set;
        }

        [XmlAttribute("msg")]
        public string Message
        {
            get;
            set;
        }
    }
}
